package com.cytech.cloudclinic.base;

import android.content.Context;
import android.widget.PopupWindow;

import com.cytech.cloudclinic.http.API;
import com.cytech.cloudclinic.http.RetrofitService;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

public class BasePopupWindow extends PopupWindow {

    private CompositeDisposable compositeDisposable;
    protected API.WAZApi apiServer = RetrofitService.getInstance().getApiService();

    public BasePopupWindow(Context context) {
        super(context);

        initPopupStyle();
    }

    private void initPopupStyle() {

    }

    public void addDisposable(Observable<?> observable, BaseObserver observer) {
        if (compositeDisposable == null) {
            compositeDisposable = new CompositeDisposable();
        }
        compositeDisposable
                .add(observable.subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeWith(observer));
    }

    private void removeDisposable() {
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

}
